//
//  MBDIconTitleCommonCell.swift
//  MasterBoy
//
//  Created by kyson on 2023/3/28.
//

import Foundation
import UIKit
import YYText
import SnapKit

class MBDIconTitleCommonCell: MBDCommonCell {

    var titleLabel : YYLabel!
    var iconImageView : UIImageView!

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.initialize()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
        self.initialize()
    }
    
    override var cellModel: Any! {
        didSet {
            let realCellModel = self.cellModel as! MBDMineCommonCellModel
            self.title = realCellModel.title
            self.accessable = realCellModel.accessory
            self.icon = realCellModel.icon
            self.location = realCellModel.location
            self.separateLine.isHidden = realCellModel.hideSeparateLine ?? true
        }
    }
    
    func initialize() {
        self.contentView.setDynamicForgroundColor()
        self.commonBackgroundView.setDynamicForgroundColor()
        
        titleLabel = YYLabel()
        self.commonBackgroundView.addSubview(titleLabel)
        
        iconImageView = UIImageView()
        self.commonBackgroundView.addSubview(iconImageView)
        
        iconImageView.snp.makeConstraints { make in
            make.centerY.equalTo(self.commonBackgroundView)
            make.left.equalTo(15)
            make.size.equalTo(CGSizeMake(18, 18))
        }
        
        titleLabel.snp.makeConstraints { make in
            make.centerY.equalTo(self.iconImageView)
            make.left.equalTo(iconImageView.snp.right).offset(8)
        }
        
        separateLine.snp.remakeConstraints { make in
            make.left.equalTo(titleLabel)
            make.height.equalTo( 1 / UIScreen.main.scale)
            make.right.equalTo(self.rightArrowImage)
            make.bottom.equalTo(self.commonBackgroundView)
        }

    }
    
    var title : String? {
        didSet {
            
            let usernameAttributeString = NSMutableAttributedString(string: self.title ?? "")
            usernameAttributeString.yy_font = UIFont.systemFont(ofSize: 14)
            usernameAttributeString.setDynamicTextColor()
            
            titleLabel.attributedText = usernameAttributeString
        }
        
        willSet {
        }
    }
    
    var icon : UIImage? {
        didSet {
            iconImageView.image = icon
        }
        
        willSet {
        }
    }
}
